<?php
// +----------------------------------------------------------------------
// | LoginController.class.php
// +----------------------------------------------------------------------
// | Author: alexander <gt199899@gmail.com>
// +----------------------------------------------------------------------
// | Data: 2014-11-7下午1:51:22
// +----------------------------------------------------------------------
// | Version: 2014-11-7下午1:51:22
// +----------------------------------------------------------------------
// | Copyright: ShowMore
// +----------------------------------------------------------------------
namespace Admin\Controller;
class LoginController extends InitController{
	
	/**
	 * index
	 * 登陆页面映射
	 * @access public
	 * @param field_type
	 * @return return_type
	 * @author alexander<gt199899@gmail.com>
	 * @version 2014-11-7 下午1:55:03
	 * @copyright Show More
	 */
	public function index(){
		$this->display();
	}
	
	/**
	 * vCode
	 * 生成验证码
	 * @access public
	 * @param field_type
	 * @return return_type
	 * @author alexander<gt199899@gmail.com>
	 * @version 2014-11-10 上午11:23:18
	 * @copyright Show More
	 */
	public function vCode(){
		\Org\Util\Image::buildImageVerify(4, 1, 'png', 60, 25, C('S_VERIFY_CODE_ID'));
	}
	
	/**
	 * loginAction
	 * 登陆动作响应
	 * @access public
	 * @param field_type
	 * @return return_type
	 * @author alexander<gt199899@gmail.com>
	 * @version 2014-11-18 上午9:59:42
	 * @copyright Show More
	 */
	public function loginAction(){
		$user = I('post.user');
		$password = I('post.pwd');
		$verify_code = I('post.vcode');
		// 检测验证码
		if(md5($verify_code) !== session(C('S_VERIFY_CODE_ID'))){
			echo json_encode(array('success'=>false, 'msg'=>'验证码不正确'));
			exit;
		}
		$user_data = D('UserInfo')->getDataByUserName($user);
		if(is_array($user_data)){
			if($user_data['P02'] === md5(md5($password).$user_data['P03'])){
				session(C('S_US_USER_ID'), $user_data['ID']);
				echo json_encode(array('success'=>true, 'msg'=>'登陆成功'));
				exit;
			}
			else{
				echo json_encode(array('success'=>false, 'msg'=>'密码不正确'));
				exit;
			}
		}
		else{
			if($user_data === 0b0){
				echo json_encode(array('success'=>false, 'msg'=>'不存在此用户名'));
				exit;
			}
			elseif($user_data === 0b1){
				echo json_encode(array('success'=>false, 'msg'=>'此账户存在异常，无法登陆，请联系系统管理员'));
				exit;
			}
		}
	}
	
}